package day12;

public class demo2 {


public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}

    public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
        ListNode cur1=pHead1;
        ListNode cur2=pHead2;
        while(cur1!=cur2){
          if (cur1==null){
              cur1=pHead1;
          }else cur1=cur1.next;
          if (cur2==null){
              cur2=pHead2;
          }else cur2=cur2.next;
        }
        return cur1;
    }
}
